package com.idis.dbApp.mapper;

import com.idis.entity.person;
import org.apache.ibatis.jdbc.SQL;


public class PersonSqlProvider {

    public String selectByProperty(person example) {
        SQL sql = new SQL();
        sql.SELECT("*");
        sql.FROM("person");

        if (example.getId() != null) {
            sql.WHERE("id=#{id,jdbcType=INTEGER}");
        }

        if (example.getName() != null) {
            sql.WHERE("name=#{name,jdbcType=VARCHAR}");
        }

        if (example.getPicture() != null) {
            sql.WHERE("picture=#{picture,jdbcType=VARCHAR}");
        }

        if (example.getContent() != null) {
            sql.WHERE("content=#{content,jdbcType=VARCHAR}");
        }

        if (example.getType() != null) {
            sql.WHERE("type=#{type,jdbcType=INTEGER}");
        }

        return sql.toString();
    }

    public String insertSelective(person record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("person");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getName() != null) {
            sql.VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getPicture() != null) {
            sql.VALUES("picture", "#{picture,jdbcType=VARCHAR}");
        }
        
        if (record.getContent() != null) {
            sql.VALUES("content", "#{content,jdbcType=VARCHAR}");
        }
        
        if (record.getType() != null) {
            sql.VALUES("type", "#{type,jdbcType=INTEGER}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(person record) {
        SQL sql = new SQL();
        sql.UPDATE("person");
        
        if (record.getName() != null) {
            sql.SET("name = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getPicture() != null) {
            sql.SET("picture = #{picture,jdbcType=VARCHAR}");
        }
        
        if (record.getContent() != null) {
            sql.SET("content = #{content,jdbcType=VARCHAR}");
        }
        
        if (record.getType() != null) {
            sql.SET("type = #{type,jdbcType=INTEGER}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}